import React, { Component } from 'react'

import Add from './components/Add/Add'
import List from './components/List/List'


export default class App extends Component {
  state = {
    comments: [
      { id: 1, name: '张三', content: 'React' },
      { id: 2, name: '李四', content: 'Vue' },
      { id: 3, name: '王五', content: 'Angular' },
    ]
  }

  // 添加评论
  addComment = (comment) => {
    const { comments } = this.state;

    this.setState({
      comments: [comment, ...comments]
    })
  }
  // 删除评论
  removeComment = (index) => {
    const comments = this.state.comments;

    this.setState({
      comments: comments.filter((comment, i) => i !== index)
    })
  }

  render() {
    return (
      <div>
        <header className="site-header jumbotron">
          <div className="container">
            <div className="row">
              <div className="col-xs-12">
                <h1>请发表对React的评论</h1>
              </div>
            </div>
          </div>
        </header>
        <div className="container">
          <Add addComment={this.addComment}></Add>
          <List comments={this.state.comments} removeComment={this.removeComment}></List>
        </div>
      </div>
    )
  }
}
